package com.ycsyxt.util;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import com.ycsyxt.entity.LoginUser;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

/**
 * @author ycs(15241496739 @ 163.com)
 * @date 2022/4/17
 **/
public class DbUtils {

    private static List<LoginUser> dbUsers = new ArrayList<>();
    private static BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();


    private static void init() {
        LoginUser user = new LoginUser("ycs", encoder.encode("123"));
        LoginUser user1 = new LoginUser("yxt", encoder.encode("123"));
        dbUsers.add(user);
        dbUsers.add(user1);
    }

    public static LoginUser getUser(String username) {
        init();
        return dbUsers.stream()
                .filter(dbuser -> dbuser.getUsername().equals(username))
                .collect(Collectors.toList()).get(0);
    }
}
